/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "基本类型.h"
#include <vector>

template<typename T>
class C_Tree
{
	C_Tree*			_m_Root;
	T*				_m_Data;
	std::vector<C_Tree*>	_m_子树;

	friend class C_Tree<T>;


public:
	C_Tree(T* data, C_Tree* root): _m_Data(data), _m_Root(root) {
		if (!_m_Root) _m_Root = this;
	}
	~C_Tree() {};

	C_Tree* f_add(T& data) {
		C_Tree<T>* tree = new C_Tree(&data, this);
		tree->_m_Root = _m_Root;
		_m_子树.push_back(tree);
		return tree;
	}

	void f_rm(uint32 id) {
		auto& it = _m_Data.begin();
		it += id;
		delete *it;
		_m_Data.erase(it);
	}

	C_Tree& operator + (uint32 id) {
		return *_m_子树[id];
	}
	C_Tree& operator - () {
		if (_m_Root) {
			return *_m_Root;
		}
		return *this;
	}

	inline uint32	f_Count() { return _m_子树.size(); }
	inline C_Tree**	f_Ds() { return &_m_子树[0]; }
	inline T*		f_D() { return _m_Data; }

	inline bool		f_是否有子分支() { return _m_子树.size(); }
};







